package com.lengxf.netty.config.initializer;

import com.lengxf.netty.config.handler.TriggerHandler;
import com.lengxf.netty.config.handler.UserHandlerHandler;
import com.lengxf.netty.config.handler.WebsocketHandshakeHandler;
import io.netty.channel.ChannelInitializer;
import io.netty.channel.ChannelPipeline;
import io.netty.channel.socket.SocketChannel;
import io.netty.handler.codec.http.HttpClientCodec;
import io.netty.handler.codec.http.HttpObjectAggregator;
import io.netty.handler.timeout.IdleStateHandler;

/**
 * @author Lengxf
 * @version 1.0.0
 * @ClassName WebSocketClientInitializer.java
 * @Description 客户端初始化
 * @createTime 2022-10-10日 10:52:00
 */
public class WebSocketClientInitializer extends ChannelInitializer<SocketChannel> {

    @Override
    protected void initChannel(SocketChannel ch) {
        ChannelPipeline pipeline = ch.pipeline();
        pipeline.addLast(new IdleStateHandler(0, 5, 0))
                .addLast(new HttpClientCodec())
                .addLast(new HttpObjectAggregator(8192))
                .addLast(new WebsocketHandshakeHandler())
                .addLast(new UserHandlerHandler())
                .addLast(new TriggerHandler());
    }

}
